package Game;

/**
 * @author lijunhao
 * 2023/7/13 练习
 * @description TODO
 * Role 角色类
 *
 *  定义一个英雄类Hero，可以通过这个类创建英雄角色
 * 属性：
 *  游戏角色拥有昵称name，等级level，血量blood，攻击力power，防御力defence，种族kind，
 * 装备Equip（只能装3个装备，初始没有装备）。
 *  方法：
 *  游戏角色拥有基本攻击方法（拥有一定几率打出暴击）attack(Monster m)，死亡判定方法isDead()，添加装备的方法addEquip(Equip e)，获取角色信息的方法show()。
 */
public class Hero {
    private String nickName;
    private int level;
    private int blood;
    private int power;
    private int defence;
    private String kind;
    private Equipmengts[] equipments = new Equipmengts[3];
    private int index;
    public void attack(Monster monster){
        int n = (int)(Math.random()*10+1);
        int block = 0;
        if(n>=3){
            block = n*3;
        }
        int blood = this.power + block - monster.getDefence();
        if(blood>0){
            monster.setBlood(monster.getBlood() - blood);
            System.out.println("当前怪兽失血量为："+blood+"，剩余血量："+monster.getBlood());
        }else{
            System.out.println("此回合攻击无效");
        }
    }

    //死亡判定方法
    public boolean isDead(){
        if(this.blood<=0){
            System.out.println("当前英雄已死亡");
            return true;
        }
        return false;
    }

    //添加装备的方法
    public void addEquip(Equipmengts e){
        if(index>=3){
            System.out.println("装备已满~");
            return;
        }
        equipments[index++] = e;
        this.power+=e.getPower();
        this.defence+=e.getDefence();
    }

    public void show(){
        System.out.println("英雄的昵称："+nickName);
        System.out.println("英雄的等级："+level);
        System.out.println("英雄的血量："+blood);
        System.out.println("英雄的攻击力："+power);
        System.out.println("英雄的防御力："+defence);
        System.out.println("英雄的类别："+kind);

        System.out.println("---------英雄装备的信息----------");
        if(equipments!=null){
            for (int i = 0; i < equipments.length; i++) {
                if(equipments[i]!=null){
                    equipments[i].show();
                }
            }
        }
    }

    public Hero() {
    }

    public Hero(String nickName, int level, int blood, int power, int defence, String kind) {
        this.nickName = nickName;
        this.level = level;
        this.blood = blood;
        this.power = power;
        this.defence = defence;
        this.kind = kind;
    }

    public Hero(String nickName, int level, int blood, int power, int defence, String kind, Equipmengts[] equipments) {
        this.nickName = nickName;
        this.level = level;
        this.blood = blood;
        this.power = power;
        this.defence = defence;
        this.kind = kind;
        this.equipments = equipments;
    }


    public String getNickName() {
        return nickName;
    }


    public void setNickName(String nickName) {
        this.nickName = nickName;
    }


    public int getLevel() {
        return level;
    }
    public void setLevel(int level) {
        this.level = level;
    }
    public int getBlood() {
        return blood;
    }
    public void setBlood(int blood) {
        this.blood = blood;
    }
    public int getPower() {
        return power;
    }
    public void setPower(int power) {
        this.power = power;
    }
    public int getDefence() {
        return defence;
    }
    public void setDefence(int defence) {
        this.defence = defence;
    }
    public String getKind() {
        return kind;
    }
    public void setKind(String kind) {
        this.kind = kind;
    }
    public Equipmengts[] getEquipments() {
        return equipments;
    }
    public void setEquipments(Equipmengts[] equipments) {
        this.equipments = equipments;
    }

    public String toString() {
        return "Hero{nickName = " + nickName + ", level = " + level + ", blood = " + blood + ", power = " + power + ", defence = " + defence + ", kind = " + kind + ", equipments = " + equipments + "}";
    }}